package use.thread.interrupt;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ExecutorInterruptExample {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newCachedThreadPool();
//        Thread thread = new Thread(new Thread() {
//            @Override
//            public void run() {
//                while (!interrupted()) {
//
//                }
//            }
//        });
        Future<?> future = executorService.submit( () -> {
            try {
                //Thread.sleep(5000);
                while (true) {
                    System.out.println("running");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        //future.cancel(true);
        System.out.println(future.isCancelled());
        //executorService.shutdownNow();
        //executorService.shutdown(); //相当于调用线程的interrupt方法
        System.out.println("Main run");
        //Thread.sleep(5000);
        System.out.println(future.isDone());

    }
}
